﻿using SqlSugar;
using SqlSugar.Extensions;

namespace DataCollection.Core.Models
{
    /// <summary>
    /// 系统设置
    ///</summary>
    [SugarTable("c_system_set")]
    public class SystemSetModel
    {
        /// <summary>
        /// 备  注:编号
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "number", IsPrimaryKey = true)]
        public int Number { get; set; }

        /// <summary>
        /// 备  注:语音播报串口地址
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "voice_port_address")]
        public string VoicePortAddress { get; set; } = null!;

        /// <summary>
        /// 备  注:语音播报波特率
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "voice_baudrate")]
        public int VoiceBaudrate { get; set; }

        /// <summary>
        /// 备  注:允许播报
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "voice_enable")]
        public int VoiceEnable { get; set; }

        /// <summary>
        /// 备  注:允许播报
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "broadcast_enable")]
        public int BroadcastEnable { get; set; }

        /// <summary>
        /// 备  注:播报间隔
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "broadcast_interval")]
        public int BroadcastInterval { get; set; }

        /// <summary>
        /// 备  注: 稳压保持时间
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "holding_time")]
        public int HoldingTime { get; set; }

        /// <summary>
        /// 备  注: 稳压保持时间
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "holding_point_count")]
        public int HoldingPointCount { get; set; }

        /// <summary>
        /// 备  注: 压力放大倍数
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "pressure_scale_multiple")]
        public int PressureScaleMultiple { get; set; }

        /// <summary>
        /// 备  注: 温度放大倍数
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "temperature_scale_multiple")]
        public int TemperatureScaleMultiple { get; set; }

        /// <summary>
        /// 备  注: 开发模式
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "development")]
        public int Development { get; set; }


        static public SystemSetModel Default() {
            SystemSetModel SetModel = new SystemSetModel();
            SetModel.Number = DateTimeOffset.Now.ToUnixTimeSeconds().ToString().ObjToInt();
            SetModel.VoicePortAddress = "COM9";
            SetModel.VoiceBaudrate = 9600;
            SetModel.VoiceEnable = 0;
            SetModel.BroadcastEnable = 0;
            SetModel.BroadcastInterval = 5;
            SetModel.HoldingTime = 120;
            SetModel.HoldingPointCount = 10;
            return SetModel;
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <returns></returns>
        public int Update()
        {
            List<SystemSetModel> list = new List<SystemSetModel>();
            list.Add(this);
            int res = SqlSugarHelper.Updateable<SystemSetModel>(list);
            return res;
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>

        public static List<SystemSetModel> List(Dictionary<string, object> where)
        {

            return SqlSugarHelper.Inquireable<SystemSetModel>(where);
        }
    }
}
